package constant.milk.toilet;

import java.util.ArrayList;
import java.util.Calendar;

import constant.milk.toilet.bean.StickerData;
import constant.milk.toilet.bean.TimerData;
import constant.milk.toilet.database.DbAdapter;
import constant.milk.toilet.database.DbSelectQuery;
import constant.milk.toilet.dialog.MilkDateDialog;
import constant.milk.toilet.info.InfoActivity;
import constant.milk.toilet.setting.SettingActivity;
import constant.milk.toilet.stats.StatsActivity;
import constant.milk.toilet.timer.TimerActivity;
import constant.milk.toilet.tip.TipActivity;
import constant.milk.toilet.util.MilkUtil;
import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.DatePickerDialog.OnDateSetListener;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.DatePicker;
import android.widget.ImageView;
import android.widget.TextView;

public class MainActivity extends SuperActivity implements OnClickListener
{
	private static final int REQUEST_CODE_INFO = 0;
	
	private View timeView;
	private View statsView;
	private View tipView;
	private View settingView;
	private TextView timeTextView;
	private TextView statsTextView;
	private TextView tipTextView;
	private TextView settingTextView;
	
	private TextView pre, next;
	private TextView todayTextView;
	
	private TextView sunday, monday, tuesday, wednesday, thursday, friday, saturday;
	
	private View calendar1_0;
	private View calendar1_1;
	private View calendar1_2;
	private View calendar1_3;
	private View calendar1_4;
	private View calendar1_5;
	private View calendar1_6;
	
	private View calendar2_0;
	private View calendar2_1;
	private View calendar2_2;
	private View calendar2_3;
	private View calendar2_4;
	private View calendar2_5;
	private View calendar2_6;
	
	private View calendar3_0;
	private View calendar3_1;
	private View calendar3_2;
	private View calendar3_3;
	private View calendar3_4;
	private View calendar3_5;
	private View calendar3_6;

	private View calendar4_0;
	private View calendar4_1;
	private View calendar4_2;
	private View calendar4_3;
	private View calendar4_4;
	private View calendar4_5;
	private View calendar4_6;
	
	private View calendar5_0;
	private View calendar5_1;
	private View calendar5_2;
	private View calendar5_3;
	private View calendar5_4;
	private View calendar5_5;
	private View calendar5_6;
	
	private View calendar6_0;
	private View calendar6_1;
	private View calendar6_2;
	private View calendar6_3;
	private View calendar6_4;
	private View calendar6_5;
	private View calendar6_6;
	
	private TextView calendar1_0TextView;
	private TextView calendar1_1TextView;
	private TextView calendar1_2TextView;
	private TextView calendar1_3TextView;
	private TextView calendar1_4TextView;
	private TextView calendar1_5TextView;
	private TextView calendar1_6TextView;
	
	private TextView calendar2_0TextView;
	private TextView calendar2_1TextView;
	private TextView calendar2_2TextView;
	private TextView calendar2_3TextView;
	private TextView calendar2_4TextView;
	private TextView calendar2_5TextView;
	private TextView calendar2_6TextView;
	
	private TextView calendar3_0TextView;
	private TextView calendar3_1TextView;
	private TextView calendar3_2TextView;
	private TextView calendar3_3TextView;
	private TextView calendar3_4TextView;
	private TextView calendar3_5TextView;
	private TextView calendar3_6TextView;

	private TextView calendar4_0TextView;
	private TextView calendar4_1TextView;
	private TextView calendar4_2TextView;
	private TextView calendar4_3TextView;
	private TextView calendar4_4TextView;
	private TextView calendar4_5TextView;
	private TextView calendar4_6TextView;
	
	private TextView calendar5_0TextView;
	private TextView calendar5_1TextView;
	private TextView calendar5_2TextView;
	private TextView calendar5_3TextView;
	private TextView calendar5_4TextView;
	private TextView calendar5_5TextView;
	private TextView calendar5_6TextView;
	
	private TextView calendar6_0TextView;
	private TextView calendar6_1TextView;
	private TextView calendar6_2TextView;
	private TextView calendar6_3TextView;
	private TextView calendar6_4TextView;
	private TextView calendar6_5TextView;
	private TextView calendar6_6TextView;
	
	private ImageView calendar1_0ImageView;
	private ImageView calendar1_1ImageView;
	private ImageView calendar1_2ImageView;
	private ImageView calendar1_3ImageView;
	private ImageView calendar1_4ImageView;
	private ImageView calendar1_5ImageView;
	private ImageView calendar1_6ImageView;
	
	private ImageView calendar2_0ImageView;
	private ImageView calendar2_1ImageView;
	private ImageView calendar2_2ImageView;
	private ImageView calendar2_3ImageView;
	private ImageView calendar2_4ImageView;
	private ImageView calendar2_5ImageView;
	private ImageView calendar2_6ImageView;
	
	private ImageView calendar3_0ImageView;
	private ImageView calendar3_1ImageView;
	private ImageView calendar3_2ImageView;
	private ImageView calendar3_3ImageView;
	private ImageView calendar3_4ImageView;
	private ImageView calendar3_5ImageView;
	private ImageView calendar3_6ImageView;

	private ImageView calendar4_0ImageView;
	private ImageView calendar4_1ImageView;
	private ImageView calendar4_2ImageView;
	private ImageView calendar4_3ImageView;
	private ImageView calendar4_4ImageView;
	private ImageView calendar4_5ImageView;
	private ImageView calendar4_6ImageView;
	
	private ImageView calendar5_0ImageView;
	private ImageView calendar5_1ImageView;
	private ImageView calendar5_2ImageView;
	private ImageView calendar5_3ImageView;
	private ImageView calendar5_4ImageView;
	private ImageView calendar5_5ImageView;
	private ImageView calendar5_6ImageView;
	
	private ImageView calendar6_0ImageView;
	private ImageView calendar6_1ImageView;
	private ImageView calendar6_2ImageView;
	private ImageView calendar6_3ImageView;
	private ImageView calendar6_4ImageView;
	private ImageView calendar6_5ImageView;
	private ImageView calendar6_6ImageView;
	
	private ArrayList<View> selectList = new ArrayList<View>();
	private ArrayList<TextView> dayList = new ArrayList<TextView>();
	private ArrayList<ImageView> imageList = new ArrayList<ImageView>();
	
	private int setYear;
	private int setMonth;
	private int setDay;
	
	private int toYear;
	private int toMonth;
	private int toDay;
	
	private boolean backFlag;
	
	private DbSelectQuery select;
	
	private MilkDateDialog dateDialog;
	
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.main_activity);
		
		backFlag = false;
		
		setFindViewId();
		setOnClick();
		setData();
	}
	
	@Override
	protected void setFindViewId()
	{
		timeView = findViewById(R.id.mainTimeView);
		statsView = findViewById(R.id.mainStatsView);
		tipView = findViewById(R.id.mainTipView);
		settingView = findViewById(R.id.mainSettingView);
		
		timeTextView = (TextView) findViewById(R.id.mainTimeTextView);
		statsTextView = (TextView) findViewById(R.id.mainStatsTextView);
		tipTextView = (TextView) findViewById(R.id.mainTipTextView);
		settingTextView = (TextView) findViewById(R.id.mainSettingTextView);
		
		pre = (TextView) findViewById(R.id.calendar_picker_pre);
		next = (TextView) findViewById(R.id.calendar_picker_next);
		todayTextView = (TextView) findViewById(R.id.calendar_picker_today);
		
		sunday = (TextView) findViewById(R.id.calendarSunday);
		monday = (TextView) findViewById(R.id.calendarMonday); 
		tuesday = (TextView) findViewById(R.id.calendarTuesday); 
		wednesday = (TextView) findViewById(R.id.calendarWednesday); 
		thursday = (TextView) findViewById(R.id.calendarThursday); 
		friday = (TextView) findViewById(R.id.calendarFriday); 
		saturday = (TextView) findViewById(R.id.calendarSaturday);
		
		calendar1_0 = findViewById(R.id.calendar1_0);
		calendar1_1 = findViewById(R.id.calendar1_1);
		calendar1_2 = findViewById(R.id.calendar1_2);
		calendar1_3 = findViewById(R.id.calendar1_3);
		calendar1_4 = findViewById(R.id.calendar1_4);
		calendar1_5 = findViewById(R.id.calendar1_5);
		calendar1_6 = findViewById(R.id.calendar1_6);
		
		calendar2_0 = findViewById(R.id.calendar2_0);
		calendar2_1 = findViewById(R.id.calendar2_1);
		calendar2_2 = findViewById(R.id.calendar2_2);
		calendar2_3 = findViewById(R.id.calendar2_3);
		calendar2_4 = findViewById(R.id.calendar2_4);
		calendar2_5 = findViewById(R.id.calendar2_5);
		calendar2_6 = findViewById(R.id.calendar2_6);
		
		calendar3_0 = findViewById(R.id.calendar3_0);
		calendar3_1 = findViewById(R.id.calendar3_1);
		calendar3_2 = findViewById(R.id.calendar3_2);
		calendar3_3 = findViewById(R.id.calendar3_3);
		calendar3_4 = findViewById(R.id.calendar3_4);
		calendar3_5 = findViewById(R.id.calendar3_5);
		calendar3_6 = findViewById(R.id.calendar3_6);
		
		calendar4_0 = findViewById(R.id.calendar4_0);
		calendar4_1 = findViewById(R.id.calendar4_1);
		calendar4_2 = findViewById(R.id.calendar4_2);
		calendar4_3 = findViewById(R.id.calendar4_3);
		calendar4_4 = findViewById(R.id.calendar4_4);
		calendar4_5 = findViewById(R.id.calendar4_5);
		calendar4_6 = findViewById(R.id.calendar4_6);
		
		calendar5_0 = findViewById(R.id.calendar5_0);
		calendar5_1 = findViewById(R.id.calendar5_1);
		calendar5_2 = findViewById(R.id.calendar5_2);
		calendar5_3 = findViewById(R.id.calendar5_3);
		calendar5_4 = findViewById(R.id.calendar5_4);
		calendar5_5 = findViewById(R.id.calendar5_5);
		calendar5_6 = findViewById(R.id.calendar5_6);
		
		calendar6_0 = findViewById(R.id.calendar6_0);
		calendar6_1 = findViewById(R.id.calendar6_1);
		calendar6_2 = findViewById(R.id.calendar6_2);
		calendar6_3 = findViewById(R.id.calendar6_3);
		calendar6_4 = findViewById(R.id.calendar6_4);
		calendar6_5 = findViewById(R.id.calendar6_5);
		calendar6_6 = findViewById(R.id.calendar6_6);
		
		calendar1_0TextView = (TextView) findViewById(R.id.calendar1_0TextView);
		calendar1_1TextView = (TextView) findViewById(R.id.calendar1_1TextView);
		calendar1_2TextView = (TextView) findViewById(R.id.calendar1_2TextView);
		calendar1_3TextView = (TextView) findViewById(R.id.calendar1_3TextView);
		calendar1_4TextView = (TextView) findViewById(R.id.calendar1_4TextView);
		calendar1_5TextView = (TextView) findViewById(R.id.calendar1_5TextView);
		calendar1_6TextView = (TextView) findViewById(R.id.calendar1_6TextView);
		
		calendar2_0TextView = (TextView) findViewById(R.id.calendar2_0TextView);
		calendar2_1TextView = (TextView) findViewById(R.id.calendar2_1TextView);
		calendar2_2TextView = (TextView) findViewById(R.id.calendar2_2TextView);
		calendar2_3TextView = (TextView) findViewById(R.id.calendar2_3TextView);
		calendar2_4TextView = (TextView) findViewById(R.id.calendar2_4TextView);
		calendar2_5TextView = (TextView) findViewById(R.id.calendar2_5TextView);
		calendar2_6TextView = (TextView) findViewById(R.id.calendar2_6TextView);
		
		calendar3_0TextView = (TextView) findViewById(R.id.calendar3_0TextView);
		calendar3_1TextView = (TextView) findViewById(R.id.calendar3_1TextView);
		calendar3_2TextView = (TextView) findViewById(R.id.calendar3_2TextView);
		calendar3_3TextView = (TextView) findViewById(R.id.calendar3_3TextView);
		calendar3_4TextView = (TextView) findViewById(R.id.calendar3_4TextView);
		calendar3_5TextView = (TextView) findViewById(R.id.calendar3_5TextView);
		calendar3_6TextView = (TextView) findViewById(R.id.calendar3_6TextView);
		
		calendar4_0TextView = (TextView) findViewById(R.id.calendar4_0TextView);
		calendar4_1TextView = (TextView) findViewById(R.id.calendar4_1TextView);
		calendar4_2TextView = (TextView) findViewById(R.id.calendar4_2TextView);
		calendar4_3TextView = (TextView) findViewById(R.id.calendar4_3TextView);
		calendar4_4TextView = (TextView) findViewById(R.id.calendar4_4TextView);
		calendar4_5TextView = (TextView) findViewById(R.id.calendar4_5TextView);
		calendar4_6TextView = (TextView) findViewById(R.id.calendar4_6TextView);
		
		calendar5_0TextView = (TextView) findViewById(R.id.calendar5_0TextView);
		calendar5_1TextView = (TextView) findViewById(R.id.calendar5_1TextView);
		calendar5_2TextView = (TextView) findViewById(R.id.calendar5_2TextView);
		calendar5_3TextView = (TextView) findViewById(R.id.calendar5_3TextView);
		calendar5_4TextView = (TextView) findViewById(R.id.calendar5_4TextView);
		calendar5_5TextView = (TextView) findViewById(R.id.calendar5_5TextView);
		calendar5_6TextView = (TextView) findViewById(R.id.calendar5_6TextView);
		
		calendar6_0TextView = (TextView) findViewById(R.id.calendar6_0TextView);
		calendar6_1TextView = (TextView) findViewById(R.id.calendar6_1TextView);
		calendar6_2TextView = (TextView) findViewById(R.id.calendar6_2TextView);
		calendar6_3TextView = (TextView) findViewById(R.id.calendar6_3TextView);
		calendar6_4TextView = (TextView) findViewById(R.id.calendar6_4TextView);
		calendar6_5TextView = (TextView) findViewById(R.id.calendar6_5TextView);
		calendar6_6TextView = (TextView) findViewById(R.id.calendar6_6TextView);
		
		calendar1_0ImageView = (ImageView) findViewById(R.id.calendar1_0ImageView);
		calendar1_1ImageView = (ImageView) findViewById(R.id.calendar1_1ImageView);
		calendar1_2ImageView = (ImageView) findViewById(R.id.calendar1_2ImageView);
		calendar1_3ImageView = (ImageView) findViewById(R.id.calendar1_3ImageView);
		calendar1_4ImageView = (ImageView) findViewById(R.id.calendar1_4ImageView);
		calendar1_5ImageView = (ImageView) findViewById(R.id.calendar1_5ImageView);
		calendar1_6ImageView = (ImageView) findViewById(R.id.calendar1_6ImageView);
		
		calendar2_0ImageView = (ImageView) findViewById(R.id.calendar2_0ImageView);
		calendar2_1ImageView = (ImageView) findViewById(R.id.calendar2_1ImageView);
		calendar2_2ImageView = (ImageView) findViewById(R.id.calendar2_2ImageView);
		calendar2_3ImageView = (ImageView) findViewById(R.id.calendar2_3ImageView);
		calendar2_4ImageView = (ImageView) findViewById(R.id.calendar2_4ImageView);
		calendar2_5ImageView = (ImageView) findViewById(R.id.calendar2_5ImageView);
		calendar2_6ImageView = (ImageView) findViewById(R.id.calendar2_6ImageView);
		
		calendar3_0ImageView = (ImageView) findViewById(R.id.calendar3_0ImageView);
		calendar3_1ImageView = (ImageView) findViewById(R.id.calendar3_1ImageView);
		calendar3_2ImageView = (ImageView) findViewById(R.id.calendar3_2ImageView);
		calendar3_3ImageView = (ImageView) findViewById(R.id.calendar3_3ImageView);
		calendar3_4ImageView = (ImageView) findViewById(R.id.calendar3_4ImageView);
		calendar3_5ImageView = (ImageView) findViewById(R.id.calendar3_5ImageView);
		calendar3_6ImageView = (ImageView) findViewById(R.id.calendar3_6ImageView);
		
		calendar4_0ImageView = (ImageView) findViewById(R.id.calendar4_0ImageView);
		calendar4_1ImageView = (ImageView) findViewById(R.id.calendar4_1ImageView);
		calendar4_2ImageView = (ImageView) findViewById(R.id.calendar4_2ImageView);
		calendar4_3ImageView = (ImageView) findViewById(R.id.calendar4_3ImageView);
		calendar4_4ImageView = (ImageView) findViewById(R.id.calendar4_4ImageView);
		calendar4_5ImageView = (ImageView) findViewById(R.id.calendar4_5ImageView);
		calendar4_6ImageView = (ImageView) findViewById(R.id.calendar4_6ImageView);
		
		calendar5_0ImageView = (ImageView) findViewById(R.id.calendar5_0ImageView);
		calendar5_1ImageView = (ImageView) findViewById(R.id.calendar5_1ImageView);
		calendar5_2ImageView = (ImageView) findViewById(R.id.calendar5_2ImageView);
		calendar5_3ImageView = (ImageView) findViewById(R.id.calendar5_3ImageView);
		calendar5_4ImageView = (ImageView) findViewById(R.id.calendar5_4ImageView);
		calendar5_5ImageView = (ImageView) findViewById(R.id.calendar5_5ImageView);
		calendar5_6ImageView = (ImageView) findViewById(R.id.calendar5_6ImageView);
		
		calendar6_0ImageView = (ImageView) findViewById(R.id.calendar6_0ImageView);
		calendar6_1ImageView = (ImageView) findViewById(R.id.calendar6_1ImageView);
		calendar6_2ImageView = (ImageView) findViewById(R.id.calendar6_2ImageView);
		calendar6_3ImageView = (ImageView) findViewById(R.id.calendar6_3ImageView);
		calendar6_4ImageView = (ImageView) findViewById(R.id.calendar6_4ImageView);
		calendar6_5ImageView = (ImageView) findViewById(R.id.calendar6_5ImageView);
		calendar6_6ImageView = (ImageView) findViewById(R.id.calendar6_6ImageView);
	}

	@Override
	protected void setOnClick()
	{
		timeView.setOnClickListener(MainActivity.this);
		statsView.setOnClickListener(MainActivity.this);
		tipView.setOnClickListener(MainActivity.this);
		settingView.setOnClickListener(MainActivity.this);
		
		pre.setOnClickListener(MainActivity.this);
		next.setOnClickListener(MainActivity.this);
		
		todayTextView.setOnClickListener(MainActivity.this);
		
		calendar1_0.setOnClickListener(MainActivity.this);
		calendar1_1.setOnClickListener(MainActivity.this);
		calendar1_2.setOnClickListener(MainActivity.this);
		calendar1_3.setOnClickListener(MainActivity.this);
		calendar1_4.setOnClickListener(MainActivity.this);
		calendar1_5.setOnClickListener(MainActivity.this);
		calendar1_6.setOnClickListener(MainActivity.this);
		
		calendar2_0.setOnClickListener(MainActivity.this);
		calendar2_1.setOnClickListener(MainActivity.this);
		calendar2_2.setOnClickListener(MainActivity.this);
		calendar2_3.setOnClickListener(MainActivity.this);
		calendar2_4.setOnClickListener(MainActivity.this);
		calendar2_5.setOnClickListener(MainActivity.this);
		calendar2_6.setOnClickListener(MainActivity.this);
		
		calendar3_0.setOnClickListener(MainActivity.this);
		calendar3_1.setOnClickListener(MainActivity.this);
		calendar3_2.setOnClickListener(MainActivity.this);
		calendar3_3.setOnClickListener(MainActivity.this);
		calendar3_4.setOnClickListener(MainActivity.this);
		calendar3_5.setOnClickListener(MainActivity.this);
		calendar3_6.setOnClickListener(MainActivity.this);
		
		calendar4_0.setOnClickListener(MainActivity.this);
		calendar4_1.setOnClickListener(MainActivity.this);
		calendar4_2.setOnClickListener(MainActivity.this);
		calendar4_3.setOnClickListener(MainActivity.this);
		calendar4_4.setOnClickListener(MainActivity.this);
		calendar4_5.setOnClickListener(MainActivity.this);
		calendar4_6.setOnClickListener(MainActivity.this);
		
		calendar5_0.setOnClickListener(MainActivity.this);
		calendar5_1.setOnClickListener(MainActivity.this);
		calendar5_2.setOnClickListener(MainActivity.this);
		calendar5_3.setOnClickListener(MainActivity.this);
		calendar5_4.setOnClickListener(MainActivity.this);
		calendar5_5.setOnClickListener(MainActivity.this);
		calendar5_6.setOnClickListener(MainActivity.this);
		
		calendar6_0.setOnClickListener(MainActivity.this);
		calendar6_1.setOnClickListener(MainActivity.this);
		calendar6_2.setOnClickListener(MainActivity.this);
		calendar6_3.setOnClickListener(MainActivity.this);
		calendar6_4.setOnClickListener(MainActivity.this);
		calendar6_5.setOnClickListener(MainActivity.this);
		calendar6_6.setOnClickListener(MainActivity.this);
	}
	
	private void setTextList()
	{
		selectList.add(calendar1_0);
		selectList.add(calendar1_1);
		selectList.add(calendar1_2);
		selectList.add(calendar1_3);
		selectList.add(calendar1_4);
		selectList.add(calendar1_5);
		selectList.add(calendar1_6);
		
		selectList.add(calendar2_0);
		selectList.add(calendar2_1);
		selectList.add(calendar2_2);
		selectList.add(calendar2_3);
		selectList.add(calendar2_4);
		selectList.add(calendar2_5);
		selectList.add(calendar2_6);
		
		selectList.add(calendar3_0);
		selectList.add(calendar3_1);
		selectList.add(calendar3_2);
		selectList.add(calendar3_3);
		selectList.add(calendar3_4);
		selectList.add(calendar3_5);
		selectList.add(calendar3_6);
		
		selectList.add(calendar4_0);
		selectList.add(calendar4_1);
		selectList.add(calendar4_2);
		selectList.add(calendar4_3);
		selectList.add(calendar4_4);
		selectList.add(calendar4_5);
		selectList.add(calendar4_6);
		
		selectList.add(calendar5_0);
		selectList.add(calendar5_1);
		selectList.add(calendar5_2);
		selectList.add(calendar5_3);
		selectList.add(calendar5_4);
		selectList.add(calendar5_5);
		selectList.add(calendar5_6);
	
		selectList.add(calendar6_0);
		selectList.add(calendar6_1);
		selectList.add(calendar6_2);
		selectList.add(calendar6_3);
		selectList.add(calendar6_4);
		selectList.add(calendar6_5);
		selectList.add(calendar6_6);
		
		dayList.add(calendar1_0TextView);
		dayList.add(calendar1_1TextView);
		dayList.add(calendar1_2TextView);
		dayList.add(calendar1_3TextView);
		dayList.add(calendar1_4TextView);
		dayList.add(calendar1_5TextView);
		dayList.add(calendar1_6TextView);
		
		dayList.add(calendar2_0TextView);
		dayList.add(calendar2_1TextView);
		dayList.add(calendar2_2TextView);
		dayList.add(calendar2_3TextView);
		dayList.add(calendar2_4TextView);
		dayList.add(calendar2_5TextView);
		dayList.add(calendar2_6TextView);
		
		dayList.add(calendar3_0TextView);
		dayList.add(calendar3_1TextView);
		dayList.add(calendar3_2TextView);
		dayList.add(calendar3_3TextView);
		dayList.add(calendar3_4TextView);
		dayList.add(calendar3_5TextView);
		dayList.add(calendar3_6TextView);
		
		dayList.add(calendar4_0TextView);
		dayList.add(calendar4_1TextView);
		dayList.add(calendar4_2TextView);
		dayList.add(calendar4_3TextView);
		dayList.add(calendar4_4TextView);
		dayList.add(calendar4_5TextView);
		dayList.add(calendar4_6TextView);
		
		dayList.add(calendar5_0TextView);
		dayList.add(calendar5_1TextView);
		dayList.add(calendar5_2TextView);
		dayList.add(calendar5_3TextView);
		dayList.add(calendar5_4TextView);
		dayList.add(calendar5_5TextView);
		dayList.add(calendar5_6TextView);
	
		dayList.add(calendar6_0TextView);
		dayList.add(calendar6_1TextView);
		dayList.add(calendar6_2TextView);
		dayList.add(calendar6_3TextView);
		dayList.add(calendar6_4TextView);
		dayList.add(calendar6_5TextView);
		dayList.add(calendar6_6TextView);
		
		imageList.add(calendar1_0ImageView);
		imageList.add(calendar1_1ImageView);
		imageList.add(calendar1_2ImageView);
		imageList.add(calendar1_3ImageView);
		imageList.add(calendar1_4ImageView);
		imageList.add(calendar1_5ImageView);
		imageList.add(calendar1_6ImageView);
		
		imageList.add(calendar2_0ImageView);
		imageList.add(calendar2_1ImageView);
		imageList.add(calendar2_2ImageView);
		imageList.add(calendar2_3ImageView);
		imageList.add(calendar2_4ImageView);
		imageList.add(calendar2_5ImageView);
		imageList.add(calendar2_6ImageView);
		
		imageList.add(calendar3_0ImageView);
		imageList.add(calendar3_1ImageView);
		imageList.add(calendar3_2ImageView);
		imageList.add(calendar3_3ImageView);
		imageList.add(calendar3_4ImageView);
		imageList.add(calendar3_5ImageView);
		imageList.add(calendar3_6ImageView);
		
		imageList.add(calendar4_0ImageView);
		imageList.add(calendar4_1ImageView);
		imageList.add(calendar4_2ImageView);
		imageList.add(calendar4_3ImageView);
		imageList.add(calendar4_4ImageView);
		imageList.add(calendar4_5ImageView);
		imageList.add(calendar4_6ImageView);
		
		imageList.add(calendar5_0ImageView);
		imageList.add(calendar5_1ImageView);
		imageList.add(calendar5_2ImageView);
		imageList.add(calendar5_3ImageView);
		imageList.add(calendar5_4ImageView);
		imageList.add(calendar5_5ImageView);
		imageList.add(calendar5_6ImageView);
		
		imageList.add(calendar6_0ImageView);
		imageList.add(calendar6_1ImageView);
		imageList.add(calendar6_2ImageView);
		imageList.add(calendar6_3ImageView);
		imageList.add(calendar6_4ImageView);
		imageList.add(calendar6_5ImageView);
		imageList.add(calendar6_6ImageView);
	}

	@Override
	protected void setData()
	{
		select = new DbSelectQuery(superContext, superDb);
		
		setTextList();
		
		timeTextView.setTextSize(TEXT_SIZE - 2);
		statsTextView.setTextSize(TEXT_SIZE - 2);
		tipTextView.setTextSize(TEXT_SIZE - 2);
		settingTextView.setTextSize(TEXT_SIZE - 2);
		
		timeTextView.setTextColor(Color.WHITE);
		statsTextView.setTextColor(Color.WHITE);
		tipTextView.setTextColor(Color.WHITE);
		settingTextView.setTextColor(Color.WHITE);
		
		sunday.setTextColor(Color.RED);
		monday.setTextColor(Color.WHITE);
		tuesday.setTextColor(Color.WHITE);
		wednesday.setTextColor(Color.WHITE); 
		thursday.setTextColor(Color.WHITE); 
		friday.setTextColor(Color.WHITE); 
		saturday.setTextColor(Color.BLUE);
		
		sunday.setTextSize(16);
		monday.setTextSize(16);
		tuesday.setTextSize(16);
		wednesday.setTextSize(16);
		thursday.setTextSize(16);
		friday.setTextSize(16); 
		saturday.setTextSize(16);
		
		calendar1_0TextView.setTextColor(Color.RED);
		calendar1_6TextView.setTextColor(Color.BLUE);
		
		calendar2_0TextView.setTextColor(Color.RED);
		calendar2_6TextView.setTextColor(Color.BLUE);
		
		calendar3_0TextView.setTextColor(Color.RED);
		calendar3_6TextView.setTextColor(Color.BLUE);
		
		calendar4_0TextView.setTextColor(Color.RED);
		calendar4_6TextView.setTextColor(Color.BLUE);
		
		calendar5_0TextView.setTextColor(Color.RED);
		calendar5_6TextView.setTextColor(Color.BLUE);
		
		calendar6_0TextView.setTextColor(Color.RED);
		calendar6_6TextView.setTextColor(Color.BLUE);
		
		Calendar cal = Calendar.getInstance();
		
		toYear = cal.get(Calendar.YEAR);
		toMonth = cal.get(Calendar.MONTH);
		toDay = cal.get(Calendar.DAY_OF_MONTH);
		
		setYear = cal.get(Calendar.YEAR);
		setMonth = cal.get(Calendar.MONTH);
		setDay = cal.get(Calendar.DAY_OF_MONTH);
		
		setCalendar(setYear, setMonth, setDay);
		
		todayTextView.setTextSize(TEXT_SIZE + 8);
	}
	
	@Override
	protected void onNewIntent(Intent intent)
	{
		super.onNewIntent(intent);
		
		super.setSettingFontSize();
		
		setTextList();
		
		timeTextView.setTextSize(TEXT_SIZE -2);
		statsTextView.setTextSize(TEXT_SIZE -2);
		tipTextView.setTextSize(TEXT_SIZE -2);
		settingTextView.setTextSize(TEXT_SIZE -2);
		
		timeTextView.setTextColor(Color.WHITE);
		statsTextView.setTextColor(Color.WHITE);
		tipTextView.setTextColor(Color.WHITE);
		settingTextView.setTextColor(Color.WHITE);
		
		sunday.setTextColor(Color.RED);
		monday.setTextColor(0xffffffff);
		tuesday.setTextColor(0xffffffff);
		wednesday.setTextColor(0xffffffff); 
		thursday.setTextColor(0xffffffff); 
		friday.setTextColor(0xffffffff); 
		saturday.setTextColor(Color.BLUE);
		
		sunday.setTextSize(16);
		monday.setTextSize(16);
		tuesday.setTextSize(16);
		wednesday.setTextSize(16);
		thursday.setTextSize(16);
		friday.setTextSize(16); 
		saturday.setTextSize(16);
		
		calendar1_0TextView.setTextColor(Color.RED);
		calendar1_6TextView.setTextColor(Color.BLUE);
		
		calendar2_0TextView.setTextColor(Color.RED);
		calendar2_6TextView.setTextColor(Color.BLUE);
		
		calendar3_0TextView.setTextColor(Color.RED);
		calendar3_6TextView.setTextColor(Color.BLUE);
		
		calendar4_0TextView.setTextColor(Color.RED);
		calendar4_6TextView.setTextColor(Color.BLUE);
		
		calendar5_0TextView.setTextColor(Color.RED);
		calendar5_6TextView.setTextColor(Color.BLUE);
		
		calendar6_0TextView.setTextColor(Color.RED);
		calendar6_6TextView.setTextColor(Color.BLUE);
		
		Calendar cal = Calendar.getInstance();
		
		toYear = cal.get(Calendar.YEAR);
		toMonth = cal.get(Calendar.MONTH);
		toDay = cal.get(Calendar.DAY_OF_MONTH);
		
		setYear = cal.get(Calendar.YEAR);
		setMonth = cal.get(Calendar.MONTH);
		setDay = cal.get(Calendar.DAY_OF_MONTH);
		
		setCalendar(setYear, setMonth, setDay);
		
		todayTextView.setTextSize(TEXT_SIZE + 8);
	}
	
	private void setCalendar(int year, int month, int day) 
	{
		for (int i = 0; i < dayList.size(); i++)
		{
			TextView tv = (TextView) dayList.get(i);
			tv.setBackgroundColor(0);
			tv.setText("");
		}
		
		for (int i = 0; i < imageList.size(); i++)
		{
			ImageView iv = (ImageView) imageList.get(i);
			iv.setImageResource(0);
		}
		
		Calendar calendar = Calendar.getInstance();
		calendar.set(Calendar.YEAR, year);
		calendar.set(Calendar.MONTH, month);
		calendar.set(Calendar.DAY_OF_MONTH, 1);

		todayTextView.setText(MilkUtil.getDateCom(year, month+1, day));

		int getDay = calendar.get(Calendar.DAY_OF_WEEK);
		
		int j = 1;

		for (int i = getDay - 1; i < calendar
				.getActualMaximum(Calendar.DAY_OF_MONTH) + getDay - 1; i++) 
		{
			View sv = selectList.get(i);
			sv.setTag(j);
			
			TextView tv = dayList.get(i);
			tv.setTextSize(TEXT_SIZE);
			
			ImageView iv = imageList.get(i);
			StickerData stickerData = select.getStickerDate(year, month, j);
			
			if (stickerData == null)
			{
				iv.setImageResource(0);
			}
			else
			{
				iv.setImageResource(MilkUtil.getSticker(stickerData.getSticker()));
			}
			
			if (j == toDay) 
			{
				if ((setYear == toYear) && (setMonth == toMonth)) 
				{
					tv.setBackgroundResource(R.drawable.calendar_today);
				}
				
				tv.setText(j + "");
			}
			else 
			{
				tv.setText(j + "");
			}
			
			j++;
		}
	}
	
	@Override
	public void onClick(View v) 
	{
		if (v.getId() == R.id.mainTimeView)
		{
			Intent intent = new Intent(superContext, TimerActivity.class);
			startActivity(intent);
		}
		else if (v.getId() == R.id.mainStatsView)
		{
			Intent intent = new Intent(superContext, StatsActivity.class);
			startActivity(intent);
		}
		else if (v.getId() == R.id.mainTipView)
		{
			Intent intent = new Intent(superContext, TipActivity.class);
			startActivity(intent);
		}
		else if (v.getId() == R.id.mainSettingView)
		{
			Intent intent = new Intent(superContext, SettingActivity.class);
			startActivity(intent);
		}
		else if (v.getId() == R.id.calendar_picker_pre) 
		{
			setMonth--;
			
			if (setMonth < 0) 
			{
				setYear--;
				setMonth = 11;
			}
			
			setCalendar(setYear, setMonth, setDay);
		} 
		else if (v.getId() == R.id.calendar_picker_next) 
		{
			setMonth++;
			
			if (setMonth > 11) 
			{
				setMonth = 0;
				setYear++;
			}
			
			setCalendar(setYear, setMonth, setDay);
		} 
		else if(v.getId() == R.id.calendar_picker_today)
		{
			dateDialog = new MilkDateDialog(superContext, 
					new MilkDateDialog.DateCollBank()
					{
						@Override
						public void getDate(int year, int month, int day)
						{
							setYear = year;
							setMonth = month;
							setDay = day;
							
							setCalendar(setYear, setMonth, setDay);
						}
					}, setYear, setMonth, toDay);
			
			dateDialog.show();
		}
		else 
		{
			if (v.getTag() != null && (Integer) v.getTag() > 0)
			{
				Intent intent = new Intent(superContext, InfoActivity.class);
				intent.putExtra(InfoActivity.YEAR, setYear);
				intent.putExtra(InfoActivity.MONTH, setMonth);
				intent.putExtra(InfoActivity.DAY, (Integer) v.getTag());
				startActivityForResult(intent, REQUEST_CODE_INFO);
			}
		}
	}
	
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data)
	{
		super.onActivityResult(requestCode, resultCode, data);
		
		if (resultCode != Activity.RESULT_OK)
		{
			return;
		}
		
		if (requestCode == REQUEST_CODE_INFO)
		{
			setCalendar(setYear, setMonth, setDay);
		}
	}
	
	private Handler backHandler = new Handler()
    {
		@Override
		public void handleMessage(Message msg)
		{
			super.handleMessage(msg);
			
			if (msg.what == 0)
			{
				backFlag = false;
			}
		}
    };
	
	@Override
	public void onBackPressed()
	{
		if (!backFlag)
		{
			MilkUtil.showToast(superContext, "뒤로 버튼을 한번더 누르시면 종료됩니다.");
			backFlag = true;
			
			backHandler.sendEmptyMessageDelayed(0, 2000);
		}
		else
		{
			superDb = DbAdapter.getInstance();
    		superDb.close();
			super.onBackPressed();
		}
	}
}
